using System;
using System.Runtime.CompilerServices;
using SiemensAmd.Mmt.McisDbModel;

namespace SiemensAmd.Mmt
{
	public class MmtToolManagerSl : MmtToolManager
	{
		public override Tuple<bool, string, string> Load(MmtToolEntity entity, int dstPlace, string userDataFormat, UserDataEntity userDataEntity, bool saveOriUserData = true, bool autoExternId = true)
		{
			Tuple<bool, string> tuple = base.HttpPost.CreateMasterData(entity.ToolIdentify, entity.DuploNo, entity.ToolType, userDataEntity);
			if (!tuple.Item1)
			{
				base.LoadToolHandler?.Invoke(arg1: false, tuple.Item2);
				return new Tuple<bool, string, string>(item1: false, tuple.Item2, "");
			}
			if (string.IsNullOrEmpty(entity.TDI_EXTERN_ID) && autoExternId)
			{
				entity.TDI_EXTERN_ID = Guid.NewGuid().ToString();
			}
			Tuple<bool, string> tuple2 = base.HttpPost.ImportTool(base.ServerNode, base.PresetterMag, entity);
			if (!tuple2.Item1)
			{
				base.LoadToolHandler?.Invoke(arg1: false, tuple2.Item2);
				return new Tuple<bool, string, string>(item1: false, tuple2.Item2, "");
			}
			int sumTime = 0;
			TDI_TOOLDATAEntity tDI_TOOLDATAEntity = base.CheckInsert(entity.TDI_EXTERN_ID, ref sumTime, 500);
			if (tDI_TOOLDATAEntity == null)
			{
				base.LoadToolHandler?.Invoke(arg1: false, "检测Presetter数据超时");
				return new Tuple<bool, string, string>(item1: false, "检测Presetter数据超时", "");
			}
			TDI_TOOLPLACEEntity tDI_TOOLPLACEEntity = base.TdiToolDataDetailDal.QueryToolPlace(tDI_TOOLDATAEntity.DbIdTDIToolData);
			Tuple<bool, string, string, string> tuple3 = base.HttpPost.LoadUnload(base.ServerNode, base.PresetterMag, tDI_TOOLPLACEEntity.PlaceNo, base.DeviceNode, base.DstMag, entity.ToolIdentify, dstPlace);
			if (!tuple3.Item1)
			{
				base.LoadToolHandler?.Invoke(arg1: false, tuple3.Item2);
				return new Tuple<bool, string, string>(item1: false, tuple3.Item2, "");
			}
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(26, 3);
			defaultInterpolatedStringHandler.AppendLiteral("发送成功请准备实时进行监控！刀具:");
			defaultInterpolatedStringHandler.AppendFormatted(entity.ToolIdentify);
			defaultInterpolatedStringHandler.AppendLiteral("DuploNo:");
			defaultInterpolatedStringHandler.AppendFormatted(entity.DuploNo);
			defaultInterpolatedStringHandler.AppendLiteral("-");
			defaultInterpolatedStringHandler.AppendFormatted(DateTime.Now);
			return new Tuple<bool, string, string>(item1: true, defaultInterpolatedStringHandler.ToStringAndClear(), tuple3.Item4);
		}
	}
}
